The following section provides an example of a possible workflow using landscape connectivity data as spatial dependencies (i.e. bound.dat). It is important to note that these are indeed examples of the software’s capabilities and are not intended to be used as scientific advice in a spatial conservation planning process.
The maps and plots shown in this tutorial were created in R using the shapefile exported from the “Plotting Options” tab of Marxan Connect. The R code used to make the plots can be revealed by clicking on the Code button below
library(sf)
library(leaflet)
library(tmap)
library(tidyverse)
library(DT)
# set default projection for leaflet
proj <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"
In this case study, we will be working with data from the Great Barrier Reef in Australia. Our represenation features consist of a subset of bioregions identified by the Great Barrier Reef Marine Park Authority. In this example, we will generate the connectivity input data using Marxan Connect.
Download the example project folder. This folder contains the Marxan Connect Project file, the input data, and the output data from this example.
Before opening Marxan Connect, let’s manually look through the ‘traditional’ Marxan files (spec.dat, puvspr.dat, bound.dat, and pu.dat) in the input folder of the CSD_landscape folder, which contain only representation targets. The planning unit file (hex_planning_units.shp) includes 653 hexagonal planning units that cover the Great Barrier Reef. We’ve identified a few bioregion types as our conservation features, for which we’ve set conservation targets.
spec.datspec <- read.csv("tutorial/CSD_landscape/input/spec.dat")
datatable(spec,rownames = FALSE, options = list(searching = FALSE))
puvspr.datThe table shown here is a trimmed version showing the first 30 rows as an example of the type of data in the puvspr.dat file. The original dataset has 974 entries.
puvspr <- read.csv("tutorial/CSD_landscape/input/puvspr.dat")
datatable(puvspr[1:30,],rownames = FALSE, options = list(searching = FALSE))
bound.datThe table shown here is a trimmed version showing the first 30 rows as an example of the type of data in the bound.dat file. The original dataset has 3600 entries.
bound <- read.csv("tutorial/CSD_landscape/input/bound.dat")
datatable(bound[1:30,],rownames = FALSE, options = list(searching = FALSE))
pu.datThe table shown here is a trimmed version showing the first 30 rows as an example of the type of data in the puvspr.dat file. The original dataset has 653 entries.
pu <- read.csv("tutorial/CSD_landscape/input/pu.dat")
datatable(pu[1:30,],rownames = FALSE, options = list(searching = FALSE))
This map shows the bioregions, which serve as conservation features in the Marxan analysis with no connectivity.
puvspr_wide <- puvspr %>%
left_join(select(spec,"id","name"),
by=c("species"="id")) %>%
select(-species) %>%
spread(key="name",value="amount")
# planning units with output
output <- read.csv("tutorial/CSD_landscape/output/pu_no_connect.csv") %>%
mutate(geometry=st_as_sfc(geometry,"+proj=longlat +datum=WGS84"),
best_solution = as.logical(best_solution)) %>%
st_as_sf() %>%
left_join(puvspr_wide,by=c("FID"="pu"))
map <- leaflet(output) %>%
addTiles()
groups <- names(select(output,-best_solution,-select_freq))[c(-1,-2)]
groups <- groups[groups!="geometry"]
for(i in groups){
z <- unlist(data.frame(output)[i])
if(is.numeric(z)){
pal <- colorBin("YlOrRd", domain = z)
}else{
pal <- colorFactor("YlOrRd", domain = z)
}
map = map %>%
addPolygons(fillColor = ~pal(z),
fillOpacity = 0.6,
weight=0.5,
color="white",
group=i,
label = as.character(z)) %>%
addLegend(pal = pal,
values = z,
title = i,
group = i,
position="bottomleft")
}
map <- map %>%
addLayersControl(overlayGroups = groups,
options = layersControlOptions(collapsed = FALSE))
for(i in groups){
map <- map %>% hideGroup(i)
}
map %>%
showGroup("BIORE_102")
The connectivity data is at the ‘heart’ of Marxan Connect’s functionality. It allows the generation of new conservation features based on connectivity metrics. Let’s examine the spatial layers we’ve added in order to incorporate connectivity into the Marxan analysis. Marxan Connect needs a shapefile for the planning units, and optionally the focus areas and avoidance areas. For simplicity, we have not included focus or avoidance areas in this tutorial. These spatial layers are shown in the map below.
# planning units
pu <- st_read("tutorial/CSD_landscape/hex_planning_units.shp") %>%
st_transform(proj)
p <- qtm(pu,fill = '#7570b3')
tmap_leaflet(p) %>%
addLegend(position = "topright",
labels = c("Planning Units"),
colors = c("#7570b3"),
title = "Layers")
IsolationByDistance.csvThe connectivity data for this analysis can be found in the IsolationByDistance.csv file in the CSD_landscape folder. This connectivity data was generated by Marxan Connect and represents the proportion of those individuals originating from a donor planning unit (which contains a particular habitat type) which arrive into a recipient planning unit (which contains that same habitat type) (i.e. a probability matrix) in a edge list with type (i.e. habitat type) format. The connectivity data generating procedure is described in more detail in the Connectivity Input section. Below is the connectivity matrix of our example conservation priority. For the sake of your web browser, this table only contains the 7 rows and columns of the connectivity matrix. The real file has 1279227 entries.
conmat <- read.csv("tutorial/CSD_landscape/IsolationByDistance.csv")
datatable(conmat[1:7,],rownames = FALSE, options = list(searching = FALSE))
Now that we have explored the input files, we are ready to open Marxan Connect and load our project. Please load the tutorial.MarCon file in the CSD_landscape folder into Marxan Connect. You should not have to change any inputs in the project, but it is important to understand what these choices entail.
Figure 1: Loading Marxan Connect tutorial .
We will now step through the Marxan Connect workflow following the work flow tabs.
Figure 2: Workflow tabs .
After loading tutorial.MarCon your Spatial Input tab should now look something like this:
Figure 3: Spatial Input tab .
Make sure that the Planning Unit Shapefile and when relevant, the, Focus Area Shapefile and Avoidance Area Shapefile correspond to the appropriate input files (the Focus and Avoidance areas are not used in this example). On this tab, you can also choose whether the Focus Area Shapefile and Avoidance Areas Shapefile should be locked in, locked out, or status-quo (i.e. the planning unit status stays the same as what is designated in the pu.dat file).
Now we are ready to proceed to the Connectivity Input tab.
Since we are working with landscape data, we choose the Landscape Input option from the Choose Connectivity Input Category dropdown menu. Alternatively, Demographic Input could be chosen (see demographic connectivity tutorial).
For the landscape connectivity approach, Marxan Connect calculates connectivity metrics from networks based either on Euclidean distance or least-cost path between the centroid of planning units. The connectivity data we use in this example was created using the “Habitat Type + Resistance” option from the second dropdown menu. We selected the “Euclidean Distance”Distance Calculation Type" to estimate the connectivity between each planning unit. We selected the bioregion_short.shp as the Habitat Type Shapefile so that pairs of planning units which contain the same habitat type are connected while others are not. The probability of connectivity then becomes \({1/distance^2}\), if pairs of planning units contain the same habitat type, and are normalized for each source planning unit so that the sum of probabilities equals 1 (i.e. row normalized). The Habitat Neighbour Buffer is the maximum distance (in meters) that neighbouring planning units could be considered directly connected. In this case, it is set to 1 meter. The Habitat Connectivity Lower Threshold is the value below which connectivity links are considered negligible and set to 0.
Since the process of creating the landscape connectivity matrix is fairly time consuming we’ve provided the pre-calculated matrix using the above options. On this tab, ensure that the Landscape Connectivity Matrix refers to the correct file. For this example, this should read IsolationByDistance.csv.
Since this data represents XXX in a matrix format, we have selected.
*******EXPLAIN OTHER POTENTIAL LANDSCAPE CONNECTIVITY DATA OPTIONS?****.
Your Connectivity Input tab should look like this (you should not have to change any settings):
Figure 4: Connectivity Input Tab .
Now proceed to the Connectivity Metrics tab.
In this example, we have chosen to incorporate landscape connectivity data as the spatial dependencies between planning units, and therefore, have selected the Connectivity as boundary option in the Planning Unit Dependency as Boundary Definition section. This option uses the strengths of connectivity as the spatial dependencies (i.e. instead of the shared boundary lengths) so it can later be exported into the bound.dat file (see Beger et al. (2010) for an example). This method assumes the user has provided appropriate connectivity data (e.g. appropriate scale, units, and rank-order).
Alternatively, landscape connectivity data could be incorporated as a discrete conservation feature. The drop down menu in the top right corner gives definitions, possible objectives and the mathematical formulations for different conservation feature options. See demographic connectivity tutorial for more information. 
Once you have selected the appropriate landscape connectivity inputs press Calculate Metrics and proceed to the Pre-Evaluation tab.
This page allows you to evaluate the metrics created on the Connectivity Metrics tab in more detail. It also allows you to choose how you would like to create the connectivity metrics file for further analysis. Since we are using connectivity as boundaries, we do not need to create new features. However, if you are using both spatial dependencies and conservation features, you will need to create features for those metrics. You may now proceed to the Marxan Files tab.
In this example, we have not created any new conservation features, so we can ignore all file inputs/exports except the Spatial Dependencies section.
Under the Spatial Dependencies (boundary.dat) File section, we can specify the name of our new boundary file. Make sure the Original Spatial Dependencies File lists the original bound.dat file, and choose a desired name for the new bound.dat file (e.g. bound_connect.dat). If both files have the same name, the original bound.dat file will be overwritten. Once the desired options have been chosen, press Export button next to the new spatial dependencies file name. This will create a new boundary file that incorporates the landscape connectivity metrics (or update the files, as it has already been created) in the input folder of the CSD_landscape folder. A pop-up window should appear signifying that the file was exported successfully.
Let’s examine the appended file.
bound_connect.datLocate the bound_connect.dat file that was created in your Marxan directory folder. This file should look like the table below. This table represents the spatial dependence boundaries between planning units as the values in the connectivity matrix from above (IsolationByDistance.csv, i.e. connectivity strength instead of boundary length).
The table shown here is a trimmed version showing the first 30 rows as an example of the type of data in the bound_connect.dat file. The original dataset has 38648 entries.
bound <- read.csv("tutorial/CSD_landscape/input/bound_connect.dat")
datatable(bound[1:30,],rownames = FALSE, options = list(searching = FALSE))
Proceed to the Run Marxan tab.
Now that the necessary connectivity files have been created, we are ready to run Marxan Connect. Make sure that Marxan Input File corresponds to the new input_connect.dat file. In this example, we have created the input_connect.dat file for you. However, when using your own data, you will need to create this file yourself (manually or with the ‘customize’ button that calls Marxan’s ‘inedit’), following the same format as the file that is provided.
Figure 7: Marxan Analysis tab .
To run Marxan Connect press the Run Marxan button in the bottom right corner of this tab. Finally, running Marxan with the connectivity conservation features and boundary definitions results in the following different Marxan solution:
# planning units with output
output <- read.csv("tutorial/CSD_landscape/output/pu_connect.csv") %>%
mutate(geometry=st_as_sfc(geometry,"+proj=longlat +datum=WGS84"),
best_solution = as.logical(best_solution)#,
# fa_included = as.logical(gsub("True",TRUE,.$fa_included)),
# aa_included = as.logical(gsub("True",TRUE,.$aa_included))
) %>%
st_as_sf()
map <- leaflet(output) %>%
addTiles()
groups <- c("best_solution","select_freq")
for(i in groups){
z <- unlist(data.frame(output)[i])
if(is.numeric(z)){
pal <- colorBin("YlOrRd", domain = z)
}else{
pal <- colorFactor("YlOrRd", domain = z)
}
map = map %>%
addPolygons(fillColor = ~pal(z),
fillOpacity = 0.6,
weight=0.5,
color="white",
group=i,
label = as.character(z)) %>%
addLegend(pal = pal,
values = z,
title = i,
group = i,
position="bottomleft")
}
map <- map %>%
addLayersControl(overlayGroups = groups,
options = layersControlOptions(collapsed = FALSE))
for(i in groups){
map <- map %>% hideGroup(i)
}
map %>%
showGroup("select_freq")
Here is the output of our example with no connectivity for comparison.
# planning units with output
output <- read.csv("tutorial/CSD_landscape/output/pu_no_connect.csv") %>%
mutate(geometry=st_as_sfc(geometry,"+proj=longlat +datum=WGS84"),
best_solution = as.logical(best_solution)) %>%
st_as_sf()
map <- leaflet(output) %>%
addTiles()
groups <- c("best_solution","select_freq")
for(i in groups){
z <- unlist(data.frame(output)[i])
if(is.numeric(z)){
pal <- colorBin("YlOrRd", domain = z)
}else{
pal <- colorFactor("YlOrRd", domain = z)
}
map = map %>%
addPolygons(fillColor = ~pal(z),
fillOpacity = 0.6,
weight=0.5,
color="white",
group=i,
label = as.character(z)) %>%
addLegend(pal = pal,
values = z,
title = i,
group = i,
position="bottomleft")
}
map <- map %>%
addLayersControl(overlayGroups = groups,
options = layersControlOptions(collapsed = FALSE))
for(i in groups){
map <- map %>% hideGroup(i)
}
map %>%
showGroup("select_freq")
Here the users can plot up to two layers of input or output data on a built in basemap (provided by the basemap package). The tab allows users to choose a few basic color, transparency, and legend positioning options, but this tab also allows users to export the output data in various formats to provide further plotting or analysis options.